package com.itheima.stargraph.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;

/**
 * Comfyui消息处理器
 *
 * @Author mr.chen
 * @Date 2025-6-8 16:12
 */
@Slf4j
@Component
public class ComfyuiMessageHandler extends TextWebSocketHandler {

    /**
     * ComfyUI客户端建立连接时触发的方法
     * @param session
     * @throws Exception
     */
    @Override
    public void afterConnectionEstablished(WebSocketSession session) throws Exception {
       log.info("星图AI作为Client与ComfyUI Server连接成功");
    }

    /**
     * ComfyUI服务端有消息变更时推送消息对应的方法
     * @param session
     * @param message
     * @throws Exception
     */
    @Override
    protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
        log.info("收到ComfyUI Server推送的消息：{}",message.getPayload());
    }
}
